package o;

import android.util.Pair;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;

public abstract class aks extends alb {
    @Nullable
    private e ˎ;

    public static final class e {
        private final TrackGroupArray ʼ;
        private final int[][][] ʽ;
        private final TrackGroupArray[] ˊ;
        private final int[] ˋ;
        @Deprecated
        public final int ˎ = this.ॱ;
        private final int[] ˏ;
        private final int ॱ;

        e(int[] iArr, TrackGroupArray[] trackGroupArrayArr, int[] iArr2, int[][][] iArr3, TrackGroupArray trackGroupArray) {
            this.ˋ = iArr;
            this.ˊ = trackGroupArrayArr;
            this.ʽ = iArr3;
            this.ˏ = iArr2;
            this.ʼ = trackGroupArray;
            this.ॱ = iArr.length;
        }

        public int ˊ() {
            return this.ॱ;
        }

        public int ˏ(int i) {
            return this.ˋ[i];
        }

        public TrackGroupArray ॱ(int i) {
            return this.ˊ[i];
        }
    }

    protected abstract Pair<abs[], akz[]> ˏ(e eVar, int[][][] iArr, int[] iArr2) throws ExoPlaybackException;

    public final void ˏ(Object obj) {
        this.ˎ = (e) obj;
    }

    public final ala ˋ(abm[] o_abmArr, TrackGroupArray trackGroupArray) throws ExoPlaybackException {
        int i;
        int[] iArr;
        int i2 = 0;
        int[] iArr2 = new int[(o_abmArr.length + 1)];
        TrackGroup[][] trackGroupArr = new TrackGroup[(o_abmArr.length + 1)][];
        int[][][] iArr3 = new int[(o_abmArr.length + 1)][][];
        for (i = 0; i < trackGroupArr.length; i++) {
            trackGroupArr[i] = new TrackGroup[trackGroupArray.ॱ];
            iArr3[i] = new int[trackGroupArray.ॱ][];
        }
        int[] ˏ = ˏ(o_abmArr);
        for (i = 0; i < trackGroupArray.ॱ; i++) {
            TrackGroup ˋ = trackGroupArray.ˋ(i);
            int ॱ = ॱ(o_abmArr, ˋ);
            if (ॱ == o_abmArr.length) {
                iArr = new int[ˋ.ॱ];
            } else {
                iArr = ˋ(o_abmArr[ॱ], ˋ);
            }
            int i3 = iArr2[ॱ];
            trackGroupArr[ॱ][i3] = ˋ;
            iArr3[ॱ][i3] = iArr;
            iArr2[ॱ] = iArr2[ॱ] + 1;
        }
        TrackGroupArray[] trackGroupArrayArr = new TrackGroupArray[o_abmArr.length];
        iArr = new int[o_abmArr.length];
        while (i2 < o_abmArr.length) {
            ॱ = iArr2[i2];
            trackGroupArrayArr[i2] = new TrackGroupArray((TrackGroup[]) anr.ॱ(trackGroupArr[i2], ॱ));
            iArr3[i2] = (int[][]) anr.ॱ(iArr3[i2], ॱ);
            iArr[i2] = o_abmArr[i2].f_();
            i2++;
        }
        e eVar = new e(iArr, trackGroupArrayArr, ˏ, iArr3, new TrackGroupArray((TrackGroup[]) anr.ॱ(trackGroupArr[o_abmArr.length], iArr2[o_abmArr.length])));
        Pair ˏ2 = ˏ(eVar, iArr3, ˏ);
        return new ala((abs[]) ˏ2.first, (akz[]) ˏ2.second, eVar);
    }

    private static int ॱ(abm[] o_abmArr, TrackGroup trackGroup) throws ExoPlaybackException {
        int i = 0;
        int length = o_abmArr.length;
        for (int i2 = 0; i2 < o_abmArr.length; i2++) {
            abm o_abm = o_abmArr[i2];
            int i3 = 0;
            while (i3 < trackGroup.ॱ) {
                int ˎ = o_abm.ˎ(trackGroup.ˊ(i3)) & 7;
                if (ˎ <= i) {
                    ˎ = length;
                    length = i;
                } else if (ˎ == 4) {
                    return i2;
                } else {
                    length = ˎ;
                    ˎ = i2;
                }
                i3++;
                i = length;
                length = ˎ;
            }
        }
        return length;
    }

    private static int[] ˋ(abm o_abm, TrackGroup trackGroup) throws ExoPlaybackException {
        int[] iArr = new int[trackGroup.ॱ];
        for (int i = 0; i < trackGroup.ॱ; i++) {
            iArr[i] = o_abm.ˎ(trackGroup.ˊ(i));
        }
        return iArr;
    }

    private static int[] ˏ(abm[] o_abmArr) throws ExoPlaybackException {
        int[] iArr = new int[o_abmArr.length];
        for (int i = 0; i < iArr.length; i++) {
            iArr[i] = o_abmArr[i].ˏॱ();
        }
        return iArr;
    }
}
